package com.liukai.exam.controller;


import com.liukai.exam.common.Result;
import com.liukai.exam.pojo.BigQuestion;
import com.liukai.exam.pojo.exam.BigQuestionManage;
import com.liukai.exam.service.IBigQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 每个试卷的大题有哪些，存放第几大题的题目类型 前端控制器
 * </p>
 *
 * @author liu kai
 * @since 2021-02-01
 */
@RestController
@RequestMapping("/exam/bigQuestion")
@Slf4j
public class BigQuestionController {

    @Autowired
    private IBigQuestionService iBigQuestionService;

    @PostMapping(value = "/addBigQuestion")
    public Result addBigQuestion(@RequestBody BigQuestionManage bigQuestionManage) {

        Long examId = bigQuestionManage.getExamId();
        int size = bigQuestionManage.getBigQuestionIndex().size();
        int count = iBigQuestionService.addBigQuestion(bigQuestionManage);
        log.info("examId" + examId);
        if (count >= size) {
            List<BigQuestion> bigQuestionList = iBigQuestionService.findBigQueById(examId);
            Result result = Result.fail(200, "新增试卷大题成功", bigQuestionList);
            return result;
        } else {
            Result result = Result.fail(404, "新增试卷信息失败,试卷名称已存在", null);
            return result;
        }
    }

}

